package util;

import java.util.HashMap;

public class StringMapper {

    //将字符串按照"Key:Value\n"的形式转换成HashMap，结尾无\n
    public static HashMap<String,String> toMap(String str){
        HashMap<String,String> map = new HashMap<>();
        String[] out = str.split("\n");
        for (String s : out) {
            int split = s.indexOf(":");
            String[] kv = s.split(":");
            map.put(kv[0],s.substring(split+1));
        }
        return map;
    }

    public static void main(String[] args) {
        HashMap<String,String> map = toMap("1:1\n2:2:2\n3\n");
        System.out.println(map);
    }
}
